package com.janus.multitypedemo.vb;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.janus.multitypedemo.R;
import com.janus.multitypedemo.bean.Ad;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by janus on 2017/7/10.
 * BannerViewBinder
 */

public class ADViewBinder extends ItemViewBinder<Ad, ADViewBinder.ViewHolder> {

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.layout_ad, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull final ViewHolder holder, @NonNull Ad item) {
        Glide.with(holder.imageView.getContext())
                .load(item.url)
                .bitmapTransform(new CenterCrop(holder.imageView.getContext()))
                .into(holder.imageView);
        holder.textView.setText(item.title);
        holder.textViewSub.setText(item.subTitle);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView textView, textViewSub;
        ImageView imageView;

        public ViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.tv_ad_title);
            textViewSub = (TextView) itemView.findViewById(R.id.tv_ad_subtitle);
            imageView = (ImageView) itemView.findViewById(R.id.iv_ad);
        }

    }
}
